//
//  ProductTableViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "ProductTableViewCell.h"

@implementation ProductTableViewCell

- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeColor" object:nil];
    
    [_backImageView release];
    [_picImageView release];
    [_headImageView release];
    [_titleLabel release];
    [_likeLabel release];
    [_logo release];
    [_docller release];
    [_labelHOBBY release];
    [_result release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //声明空字符串
         self.result = @"";
        
        [self createCell];
        [self create];
        
        
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"yeJianMoShi"] isEqualToString:@"isDay"]) {
            
            _backImageView.backgroundColor = [UIColor whiteColor];
            _labelHOBBY.textColor = [UIColor lightGrayColor];
            _likeLabel.textColor = [UIColor lightGrayColor];
        }else{
            _likeLabel.textColor = [UIColor whiteColor];
            _labelHOBBY.textColor = [UIColor whiteColor];

            _backImageView.backgroundColor = [UIColor lightGrayColor];
        }

        
        
    }
    
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColor:) name:@"yeJianMoShi" object:nil];
    
    return self;
}

- (void)changeColor:(NSNotification *)notification{
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"yeJianMoShi"]isEqualToString:@"isNight"]) {
       _backImageView.backgroundColor = [UIColor lightGrayColor];
        _likeLabel.textColor = [UIColor whiteColor];
        _labelHOBBY.textColor = [UIColor whiteColor];
    }else{
        _labelHOBBY.textColor = [UIColor lightGrayColor];
        _likeLabel.textColor = [UIColor lightGrayColor];
        _backImageView.backgroundColor = DAYCOLOR;
        
        
    }
    
    
}



- (void)createCell{
    
    self.backImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_backImageView];
    [_backImageView release];
    
    self.picImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_picImageView];
    [_picImageView release];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    self.headImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_headImageView];
    [_headImageView release];
    
    self.labelHOBBY = [[UILabel alloc] init];
    [self.contentView addSubview:_labelHOBBY];
    [_labelHOBBY release];
    
    self.likeLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_likeLabel];
    [_likeLabel release];
    
   
    
    self.logo = [[UILabel alloc] init];
    [self.contentView addSubview:_logo];
    [_logo release];
    
    self.docller = [[UILabel alloc] init];
    [self.contentView addSubview:_docller];
    [_docller release];
    
    
    self.logo = [[UILabel alloc] init];
    [self.contentView addSubview:_logo];
    [_logo release];
    
    
    self.docller = [[UILabel alloc] init];
    [self.contentView addSubview:_docller];
    [_docller release];
    
}

- (void)setModel:(Product *)model{
    
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    
    [self setValues];
    
}

- (void)setValues{
    
 
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:_model.title_page] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    _titleLabel.text = _model.title;
    
    
    
    NSString *str = [_model.like_count stringValue];
    NSString *str1 = _model.address;
    _likeLabel.text = [NSString stringWithFormat:@"%@ * %@人喜欢", str1, str];
    
    NSArray *arr = _model.tab_list;
   
    for (NSString *str in arr) {
        
        _result = [_result stringByAppendingFormat:@"【 %@ 】", str];
    }
    
    _labelHOBBY.text = _result;

    NSDictionary *dic = _model.user;
    
    [_headImageView sd_setImageWithURL:[NSURL URLWithString:dic[@"avatar_l"]] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    
    _logo.text = [NSString stringWithFormat:@"$"];
    
    _docller.text = _model.price;
    
    
}



- (void)create{
    
    _backImageView.frame = CGRectMake(10, 10,[UIScreen mainScreen].bounds.size.width - 20 , 280);
    _backImageView.backgroundColor = [UIColor whiteColor];
    _backImageView.layer.cornerRadius = 20;
    _backImageView.layer.masksToBounds = YES;
    _backImageView.layer.shadowRadius = 100;
    _backImageView.layer.shadowColor = [UIColor yellowColor].CGColor;
    _picImageView.frame = CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width - 20, 175);
    
    

    _picImageView.layer.cornerRadius = 20;
    _picImageView.layer.masksToBounds = YES;
    
    _titleLabel.frame = CGRectMake(20, 190,  [UIScreen mainScreen].bounds.size.width - 140 - 20 - 20, 50);
    _titleLabel.textColor = [UIColor blackColor];
    _titleLabel.numberOfLines = 2;
    _titleLabel.font = [UIFont systemFontOfSize:15];
    
    _headImageView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 130, 155, 70, 70);
    _headImageView.layer.cornerRadius = 35;
    _headImageView.layer.masksToBounds = YES;
    _headImageView.layer.borderWidth = 3;
    _headImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    
   
    _likeLabel.frame = CGRectMake(23, 240, 260, 30);
    _likeLabel.numberOfLines = 2;
    _likeLabel.font = [UIFont systemFontOfSize:12];
    _likeLabel.textColor = [UIColor lightGrayColor];
    _labelHOBBY.frame = CGRectMake(20, 259, 280, 40);
    _labelHOBBY.numberOfLines = 1;
    _labelHOBBY.font = [UIFont systemFontOfSize:11];
    _labelHOBBY.textColor = [UIColor lightGrayColor];
    
    
    _logo.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 80, 220, 20, 20);
    _logo.font = [UIFont systemFontOfSize:15];
    _logo.textColor = [UIColor redColor];
    _docller.frame = CGRectMake([UIScreen mainScreen].bounds.size.width-72 ,230, 80, 20);
    _docller.font = [UIFont systemFontOfSize:20];
    _docller.textColor = [UIColor redColor];
    
}





- (void)awakeFromNib {
    // Initialization code
    
    
    


}




- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
